import { IContext, IPanelRawItemControllerParams, IParam } from '@/core/interface';
import { PanelDetailController } from './panel-detail-controller';

/**
 * 面板直接内容控制器
 *
 * @export
 * @class PanelRawItemController
 * @extends {PanelDetailController}
 */
export class PanelRawItemController extends PanelDetailController {
	/**
	 * 导航数据（用于导航区占位）
	 *
	 * @private
	 * @type {*}
	 * @memberof PanelRawItemController
	 */
	public navData: any = {};

	/**
	 * 绘制模式
	 *
	 * @private
	 * @type {('TEXT' | 'HEADING1' | 'HEADING2' | 'HEADING3' | 'HEADING4' | 'HEADING5' | 'HEADING6' | 'PARAGRAPH')}
	 * @memberof PanelRawItemController
	 */
	public renderMode:
		| 'TEXT'
		| 'HEADING1'
		| 'HEADING2'
		| 'HEADING3'
		| 'HEADING4'
		| 'HEADING5'
		| 'HEADING6'
		| 'PARAGRAPH' = 'TEXT';

	/**
	 * 内容类型
	 *
	 * @private
	 * @type {('RAW' | 'HTML' | 'IMAGE' | 'MARKDOWN')}
	 * @memberof PanelRawItemController
	 */
	public contentType: 'RAW' | 'HTML' | 'IMAGE' | 'MARKDOWN' = 'RAW';

	/**
	 * 直接内容
	 *
	 * @type {string}
	 * @memberof PanelRawItemController
	 */
	public rawContent!: string;

	/**
	 * html内容
	 *
	 * @type {string}
	 * @memberof PanelRawItemController
	 */
	public htmlContent!: string;

	/**
	 * 换行模式{WRAP：换行、 NOWRAP：不换行 }
	 *
	 * @type {(string | 'WRAP' | 'NOWRAP')}
	 * @memberof PanelRawItemController
	 */
	public wrapMode: string | 'WRAP' | 'NOWRAP' = 'WRAP';

	/**
	 * 文本垂直对齐模式{TOP：上对齐、 MIDDLE：居中、 BOTTOM：下对齐 }
	 *
	 * @type {(string | 'TOP' | 'MIDDLE' | 'BOTTOM')}
	 * @memberof PanelRawItemController
	 */
	public vAlign: string | 'TOP' | 'MIDDLE' | 'BOTTOM' = 'MIDDLE';

	/**
	 * 文本水平对齐模式{LEFT：左对齐、 CENTER：居中、 RIGHT：右对齐、 JUSTIFY：两端对齐 }
	 *
	 * @type {(string | 'LEFT' | 'CENTER' | 'RIGHT' | 'JUSTIFY')}
	 * @memberof PanelRawItemController
	 */
	public hAlign: string | 'LEFT' | 'CENTER' | 'RIGHT' | 'JUSTIFY' = 'LEFT';

	/**
	 * Creates an instance of PanelRawItemController.
	 * @param {*} [IPanelRawItemControllerParams]
	 * @memberof PanelRawItemController
	 */
	constructor(opts: IPanelRawItemControllerParams, context: IContext, viewParams: IParam) {
		super(opts, context, viewParams);
		this.renderMode = opts.renderMode ? opts.renderMode : 'TEXT';
		this.contentType = opts.contentType ? opts.contentType : 'RAW';
		this.rawContent = opts.rawContent;
		this.htmlContent = opts.htmlContent;
		this.wrapMode = opts.wrapMode ? opts.wrapMode : 'WRAP';
		this.vAlign = opts.vAlign ? opts.vAlign : 'MIDDLE';
		this.hAlign = opts.hAlign ? opts.hAlign : 'LEFT';
	}

	/**
	 * 设置导航数据
	 *
	 * @param {*} value
	 * @memberof PanelRawItemController
	 */
	setNavData(value: any) {
		this.navData = value;
	}

	/**
	 * 获取导航数据
	 *
	 * @return {*}
	 * @memberof PanelRawItemController
	 */
	getNavData() {
		return this.navData;
	}

	/**
	 * 获取动态导航模式（DYNAMICCOMP：动态组件 ROUTEVIEW：路由出口）
	 *
	 * @readonly
	 * @type {('DYNAMICCOMP' | 'ROUTEVIEW')}
	 * @memberof PanelRawItemController
	 */
	get dynaNavMode(): 'DYNAMICCOMP' | 'ROUTEVIEW' {
		return this.viewType === 'APPINDEXVIEW' ? 'ROUTEVIEW' : 'DYNAMICCOMP';
	}

	/**
	 * 是否启用动态缓存
	 *
	 * @readonly
	 * @type {boolean}
	 * @memberof PanelRawItemController
	 */
	get enableCache(): boolean {
		if (
			this.viewType === 'APPINDEXVIEW' &&
			this.panel &&
			this.panel.store.layoutModelDetails
		) {
			const navPos = Object.values(this.panel.store.layoutModelDetails).find(
				(item: any) => {
					return item.predefinedType === 'NAV_TABS';
				}
			);
		}
		return false;
	}

	/**
	 * 获取元素类名
	 *
	 * @return {*}  {IParam}
	 * @memberof PanelRawItemController
	 */
	public getClassNames(): IParam {
		const classNames = super.getClassNames();
		Object.assign(classNames, this.getBoxContentClassNames());
		Object.assign(classNames, this.getRenderModeClassNames());
		return classNames;
	}

	/**
	 * 获取文本内容布局类名
	 *
	 * @protected
	 * @return {*} 
	 * @memberof PanelRawItemController
	 */
	protected getBoxContentClassNames() {
		const classNames = {};
		if (this.wrapMode) {
			Object.assign(classNames, { [`wrap--${this.wrapMode.toLowerCase()}`]: true });
		}
		if (this.hAlign) {
			Object.assign(classNames, { [`text-halign--${this.hAlign.toLowerCase()}`]: true });
		}
		if (this.vAlign) {
			Object.assign(classNames, { [`text-valign--${this.vAlign.toLowerCase()}`]: true });
		}
		return classNames;
	}

    /**
	 * 获取文本绘制模式类名
	 *
	 * @protected
	 * @return {*} 
	 * @memberof PanelRawItemController
	 */
    protected getRenderModeClassNames() {
        const classNames = {};
        if (this.renderMode) {
            Object.assign(classNames, { [`render-mode--${this.renderMode.toLowerCase()}`]: true });
        }
		return classNames;
    }
}
